package stack.offical;

import java.util.Stack;

/**
 * @BelongsProject: leetcode
 * @BelongsPackage: stack.mine
 * @Author: Administrator
 * @CreateTime: 2018-12-09 16:42
 * @Description: ${Description}
 */
public class StackToQueue<E> {
    Stack<Integer> in = null;
    Stack<Integer> out = null;
    public StackToQueue() {
        in = new Stack<>();
        out = new Stack<>();
    }
    public void push(int x) {
        in.push(x);
    }
    public int pop() {
        peek();
        return out.pop();
    }
    public int peek() {//不空的时候，直接查询返回即可
        if(out.isEmpty())//空的时候，再倒换stack
            while(!in.isEmpty())
                out.push(in.pop());
        return out.peek();
    }
    public boolean empty() {
        return in.isEmpty() && out.isEmpty();
    }

    public static void main(String[] args) {
        StackToQueue stackToQueue=new StackToQueue();
        stackToQueue.push(1);
        stackToQueue.push(2);
        stackToQueue.pop();
        stackToQueue.peek();
    }
}
